Imports System.IO
''' <summary>
''' main class to use the decompile
''' </summary>
''' <remarks>makes use of <see cref="clsDecompile"></see> and <see cref="clsWord"></see></remarks>
Public Class clsDecompileAndExport
    ''' <summary>
    ''' feedback about processing 
    ''' </summary>
    Public Event ProcessFileIntoWord As EventHandler(Of ProcessFileEventArgs)
    ''' <summary>
    ''' from this class we have the word transformation
    ''' and we catch the events to pass to the caller
    ''' </summary>    
    Dim WithEvents w As clsWord = New clsWord
    ''' <summary>
    ''' main function - decompile and exports
    ''' </summary>
    ''' <param name="ChmFile">CHM file to be decompiled</param>
    ''' <param name="DocFile">name of doc file to be saved</param>
    ''' <remarks>the doc file must not exists</remarks>
    Public Sub DecompileAndExport(ByVal ChmFile As String, ByVal DocFile As String)
        Try

            
            Dim d As clsDecompile = New clsDecompile
            Dim strHHC As String = d.DecompileChm(ChmFile)
            w.AddToWord(strHHC, DocFile)
        Catch ex As Runtime.InteropServices.COMException
            Throw New clsError("Com exception:" + ex.Message, ErrorsOcurred.ComError)
        End Try

    End Sub
    ''' <summary>
    ''' decompile and create a new doc file with same name as chm file
    ''' </summary>
    ''' <param name="ChmFile">name of chm file</param>
    ''' <remarks></remarks>
    Public Sub DecompileAndExport(ByVal ChmFile As String)
        Dim f As FileInfo = New FileInfo(ChmFile)
        Dim DocFile As String = f.Directory.FullName        
        DocFile = Path.Combine(DocFile, Path.GetFileNameWithoutExtension(ChmFile))
        DocFile += ".doc"
        DecompileAndExport(ChmFile, DocFile)
    End Sub
    ''' <summary>
    ''' raising the event to the caller
    ''' </summary>
    ''' <param name="sender">clsWord</param>
    ''' <param name="e">the file name, the file number</param>
    Private Sub w_ProcessFile(ByVal sender As Object, ByVal e As ProcessFileEventArgs) Handles w.ProcessFile
        RaiseEvent ProcessFileIntoWord(Me, New ProcessFileEventArgs(e.FileNameProcessed, e.FileNumberProcessed))
    End Sub
End Class
